package org.tsinghua.answer.domain.question;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import org.tsinghua.answer.domain.entity.BaseEntity;
import org.tsinghua.answer.domain.user.User;
import org.tsinghua.answer.utils.Identities;

@Entity
public class Reply extends BaseEntity {

	@ManyToOne(optional = false)
	@JoinColumn(name="question_id")
	private Question question;
	@Transient
	private String questionId;
	@OneToOne
	@JoinColumn(name="creator_id")
	private User creator;
	@Transient
	private String creatorId;
	private String replyId;	//如果是回复某条评论，则记录所回复评论的id
	private String replyUserId;
	private String content;
	
	public Reply(){}
	
	public Reply(User creator, Question question, String content) {
		setId(Identities.uuid2());
		setCreator(creator);
		setQuestion(question);
		setContent(content);
	}
	
	public Question getQuestion() {
		return question;
	}
	public void setQuestion(Question question) {
		this.question = question;
	}
	public String getQuestionId() {
		if(question != null) {
			return question.getId();
		}
		return questionId;
	}
	public void setQuestionId(String questionId) {
		this.questionId = questionId;
	}
	public User getCreator() {
		return creator;
	}
	public void setCreator(User creator) {
		this.creator = creator;
	}
	public String getCreatorId() {
		return creatorId;
	}
	public void setCreatorId(String creatorId) {
		this.creatorId = creatorId;
	}
	public String getReplyId() {
		return replyId;
	}
	public void setReplyId(String replyId) {
		this.replyId = replyId;
	}
	public String getReplyUserId() {
		return replyUserId;
	}
	public void setReplyUserId(String replyUserId) {
		this.replyUserId = replyUserId;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
}
